Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make generated require() ESM compatible #3235

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bdezso
Copy link

@bdezso bdezso commented Jan 12, 2025

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our guidelines: NestJS Contribution Guide
  • Tests have been added (for bug fixes and/or features)
  • Documentation has been added or updated (for bug fixes and/or features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional or API changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

NestJS does not officially support ESM. I have a project that successfully uses ESM with a custom fork, but in this Swagger plugin, the only incompatibility I found is that the generated code uses require without file extensions.

  • Prior to Node.js 22, require could not import ES modules.
  • As of Node.js 22, require can import ES modules, but missing file extensions continue to cause issues.

Issue Number: N/A

What is the new behavior?

This PR adds the appropriate file extension in the generated code based on the input extension (.cts, .mts, or .ts), thereby improving compatibility with ESM.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

I am a new NestJS user who has integrated it into an existing ESM-based project. Currently, I rely on a monkey-patch workaround, but I would prefer to avoid such hacky solutions. This PR addresses that concern by providing a more robust and maintainable approach.

@bdezso bdezso force-pushed the esm-compatible-require branch from 4b17f42 to 12cc1cf Compare January 12, 2025 22:03
@bdezso bdezso changed the title feat: make generated require ESM compatible feat: make generated require() ESM compatible Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant